﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace GiaoDien
{
    class DataProvider
    {
        public static OleDbConnection taoKetNoi()
        {
            try
            {
                string sConString = @"Provider=Microsoft.Jet.OleDb.4.0; Data Source=..\..\QLnhasach.mdb";
                OleDbConnection con = new OleDbConnection(sConString);
                con.Open();
                return con;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        public static DataTable layDataTable(string sQuery, OleDbConnection con)
        {
            try
            {
                DataTable dt = new DataTable();
                OleDbDataAdapter da = new OleDbDataAdapter(sQuery, con);
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        public static bool executeNonQuery(string sQuery, OleDbConnection con)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand(sQuery, con);
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static void dongKetNoi(OleDbConnection con)
        {
            con.Close();
        }
    }
}
